use rspc::Type;
use serde::Serialize;

use crate::record::{RecordParams, RecordManager, SaveRecordData, RecordLatest};

use super::{RouterBuilder, utils::LibraryRequest};

pub(crate) fn mount() -> RouterBuilder {
    return RouterBuilder::new()
        .query("version", |t| {
            #[derive(Serialize, Type)]
			pub struct BuildInfo {
				version: &'static str,
			}

			t(|_, _: ()| BuildInfo {
				version: "0.0.1",
			})
        })
        .library_query("get", |t| {
            t(|_, args: RecordParams, library| async move {
                Ok(RecordManager::get(library.db, args).await?)
            })
        })
        .library_mutation("save", |t| {
            t(|_, args: SaveRecordData, library| async move {
                Ok(RecordManager::save(library.db, args).await?)
            })
        })
        .library_query("latest", |t| {
            t(|_, args: RecordLatest, library| async move {
                Ok(RecordManager::latest(library.db, args).await?)
            })
        });
}
